package com.wisezone.demo0215;

import com.sun.corba.se.impl.orbutil.ObjectUtility;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class TcpServer {
    public static void main(String[] args) {

        try {
            //启动ServerSocket
            ServerSocket serverSocket=new ServerSocket(5090);
            //接受客服端请求
            Socket socket=serverSocket.accept();

            //接收客户端消息
            InputStream is=socket.getInputStream();
            //发送消息给客户端
            OutputStream os=socket.getOutputStream();
            byte[] b=new byte[512];
            int num=is.read(b);

            String str=new String(b,0,num);
            System.out.println(str);
            String s=str+" too";
            os.write(s.getBytes());
            os.flush();
            socket.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
